/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.gui;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import javax.swing.event.TableModelListener;
import model.Artist;
import model.ArtistModel;

/**
 *
 * @author Bro
 */
public class TableArtist implements javax.swing.table.TableModel {

    private ArrayList artists = new ArrayList();
    private Set<TableModelListener> listeners = new HashSet<TableModelListener>();
    public ArrayList columns = null;

    public String getColumnName(int columnIndex) {
        return columns.get(columnIndex).toString();
    }

    public Class<?> getColumnClass(int columnIndex) {
        return columns.get(columnIndex).getClass();
    }

    public int getColumnCount() {
        return columns.size();
    }

    public void addTableModelListener(TableModelListener listener) {
        listeners.add(listener);
    }

    public void removeTableModelListener(TableModelListener listener) {
        listeners.remove(listener);
    }

    public int getRowCount() {
        return artists.size();
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Artist ar = (Artist) artists.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return rowIndex + 1;
            case 1:
                return ar.getName();
        }
        return "";
    }

    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        Artist ar = (Artist) artists.get(rowIndex);
        switch (columnIndex) {
            case 1:
                ar.setName((String) aValue.toString());
                return;
        }
    }

    public TableArtist(ArrayList items, ArrayList columns) {
        artists = items;
        this.columns = columns;
    }
    
    public Artist getSelectedItem(int index) {
        return (Artist) artists.get(index);
    }
}
